package com.app.micaihu.view.army.adapter

import android.widget.ImageView
import com.app.micaihu.R
import com.app.micaihu.custom.view.AttentionView
import com.app.micaihu.view.bean.ArmyMember
import com.app.micaihu.view.utils.loadCircleImage
import com.app.utils.biz.Biz
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * 军团成员列表适配器
 */
class ArmyMemberListAdapter : BaseQuickAdapter<ArmyMember.Member, BaseViewHolder>(R.layout.army_member_list_item), LoadMoreModule {

    override fun convert(holder: BaseViewHolder, item: ArmyMember.Member) {
        holder.apply {
            getView<AttentionView>(R.id.tvAttention).tag = item
            getView<ImageView>(R.id.ivHeadPic).loadCircleImage(item.avatar, R.drawable.user_head_def)
            setText(R.id.tvNickName, item.nickname)
            if (item.grade.isEmpty()) {
                setGone(R.id.tvGrade, true)
            } else {
                setVisible(R.id.tvGrade, true)
                setText(R.id.tvGrade, item.grade)
            }
            if (item.showSelect) {
                setVisible(R.id.ivSelect, true)
                if (item.select) {
                    setImageResource(R.id.ivSelect, R.mipmap.army_member_select_on)
                } else {
                    setImageResource(R.id.ivSelect, R.mipmap.army_member_select_off)
                }
            } else {
                setGone(R.id.ivSelect, true)
            }
        }

    }

    fun setShowSelect(showSelect: Boolean) {
        for (item in data) {
            item.showSelect = showSelect
        }
        notifyDataSetChanged()
    }

    /**
     * 返回需要删除的uid , 分割
     */
    fun getSelectUid(): String {
        var uidStr = ""
        for ((index, item) in data.withIndex()) {
            if (item.select) {
                uidStr = if (index == 0) {
                    uidStr.plus(item.uid)
                } else {
                    uidStr.plus(",").plus(item.uid)
                }
            }
        }
        return uidStr
    }
}